package com.rongzhe.house.ui.activity;

import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.rongzhe.house.R;
import com.rongzhe.house.entity.voo.AppoiintmentInfo;
import com.rongzhe.house.entity.voo.OrderVo;
import com.rongzhe.house.presenter.OrderListPresenter;
import com.rongzhe.house.ui.adapter.OrderAdapter;
import com.rongzhe.house.ui.view.smoothlist.SmoothListView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by huang on 2018/1/22.
 */

public class OrderListActivity extends BaseActivity<OrderListPresenter> {
    @BindView(R.id.radio_unfinished)
    RadioButton radioUnfinished;
    @BindView(R.id.radio_finished)
    RadioButton radioFinished;
    @BindView(R.id.container_header)
    RadioGroup containerHeader;
    @BindView(R.id.list_order)
    SmoothListView listOrder;
    @BindView(R.id.text_empty)
    TextView textEmpty;
    private OrderAdapter mOrderAdapter;

    @Override
    protected OrderListPresenter createPresenter() {
        return new OrderListPresenter(this);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_order);
        ButterKnife.bind(this);
        mOrderAdapter = new OrderAdapter(this, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String orderId = (String) v.getTag();
                mPresenter.doStartPay(orderId);
            }
        });
        listOrder.setAdapter(mOrderAdapter);
        radioUnfinished.setChecked(true);
        containerHeader.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == R.id.radio_unfinished) {
                    mPresenter.loadData(false);
                } else {
                    mPresenter.loadData(true);
                }
            }
        });
    }

    public void setData(List<OrderVo> data) {
        mOrderAdapter.setDatas(data);
    }

    public void visibleEmptyView(boolean visibility) {
        textEmpty.setVisibility(visibility ? View.VISIBLE : View.GONE);
        listOrder.setVisibility(visibility ? View.GONE : View.VISIBLE);
    }

    @Override
    protected String getActionTitle() {
        return getString(R.string.my_order_list);
    }
}
